package com.chenjj.java.test.jdbc;

import com.chenjj.java.jdbc.DBUtil;
import org.junit.Test;

import java.math.BigDecimal;
import java.sql.*;
import java.util.List;
import java.util.Map;

public class JDBCTester {
    @Test
    public  void test1() throws ClassNotFoundException, SQLException {
        String url = "jdbc:postgresql://10.30.202.29:20051/hivemeta";
        String user = "hive";
        String password = "HiveUser@";
        String driver = "org.postgresql.Driver";

        Class.forName(driver);
        Connection connection = DriverManager.getConnection(url, user , password);

        PreparedStatement ps = connection.prepareStatement("select * from TBLS");
        ResultSet set =  ps.executeQuery();
        while (set.next()){
            System.out.println(set.getObject(9));
        }

    }

    @Test
    public  void test2() throws ClassNotFoundException, SQLException, InterruptedException {
        String url = "jdbc:oracle:thin:@10.30.200.129:1521/ORCLPDB1";
        String user = "sunline";
        String password = "sunline";
        String driver = "oracle.jdbc.OracleDriver";

        Class.forName(driver);
        Connection connection = DriverManager.getConnection(url, user , password);
        PreparedStatement ps;
        while (true){
            Thread.sleep(2000);

            BigDecimal max = new BigDecimal(10000000.00);
            BigDecimal min = new BigDecimal(1000000.00);;
            // random后面 x 代表取的个数  + 后面代表最小取值
            int random = (int) (Math.random() * (max.doubleValue() - min.doubleValue() + 1) + min.doubleValue());

            System.out.println(random);
            ps = connection.prepareStatement("UPDATE SUNLINE.S_CMIS_LN_DUE SET CRT_BAL = CRT_BAL +"+random+"  WHERE DUE_NO ='HB201807181904449014'");
            ps.executeUpdate();
            ps.close();
        }


    }
}
